import 'package:flutter/material.dart';
import 'package:flutter_09_game/base/widget/base_get_builder.dart';
import 'package:flutter_09_game/config/app_color.dart';
import 'package:flutter_09_game/config/app_language.dart';
import 'package:flutter_09_game/generated/assets.dart';
import 'package:flutter_09_game/generated/locales.g.dart';
import 'package:flutter_09_game/widgets/appbar/common_app_bar.dart';
import 'package:flutter_09_game/widgets/button/debounce_gesture_detector.dart';
import 'package:flutter_09_game/widgets/image/auto_image.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import 'profile_language_logic.dart';

class ProfileLanguagePage extends StatelessWidget {
  ProfileLanguagePage({super.key});

  final ProfileLanguageLogic logic = Get.put(ProfileLanguageLogic());

  @override
  Widget build(BuildContext context) {
    return BaseGetBuilder<ProfileLanguageLogic>(
        appBar: CommonAppBar(title: LocaleKeys.multiLanguage.tr),
        builder: (_) {
          Locale? locale = Get.locale;
          bool isSimplifiedChinese = locale?.countryCode != 'TW';
          return Container(
            padding: EdgeInsets.all(16.w),
            child: Column(
              children: [
                DebounceGestureDetector(
                  onTap: () {
                    AppLanguage.changeLanguage(const Locale('zh', 'CN'));
                    logic.update();
                  },
                  // onTap: () => logic.goToEditUserName(),
                  child: Container(
                    padding:
                        EdgeInsets.symmetric(horizontal: 12.w, vertical: 12.w),
                    decoration: BoxDecoration(
                      color: AppColor.navBgColor,
                      borderRadius: BorderRadius.circular(12.w),
                    ),
                    child: Row(
                      children: [
                        // 左侧标签
                        SizedBox(
                            height: 48.w,
                            child: Align(
                              alignment: Alignment.centerLeft,
                              child: Text(
                                LocaleKeys.simplifiedChinese.tr,
                                style: TextStyle(
                                  fontSize: 14.sp,
                                  fontWeight: FontWeight.w400,
                                  color: AppColor.textPrimary.withOpacity(0.94),
                                ),
                              ),
                            )),
                        16.horizontalSpace,
                        const Spacer(),
                        // Locale('zh', 'CN'), // 简体
                        // Locale('zh', 'TW'), // 繁体
                        AutoImage(
                          isSimplifiedChinese
                              ? Assets.commonCheckboxSel
                              : Assets.commonCheckboxNor,
                          width: 20.w,
                          height: 20.w,
                        ),
                      ],
                    ),
                  ),
                ),
                12.verticalSpaceFromWidth,
                DebounceGestureDetector(
                  onTap: () {
                    AppLanguage.changeLanguage(const Locale('zh', 'TW'));
                    logic.update();
                  },

                  child: Container(
                    padding:
                        EdgeInsets.symmetric(horizontal: 12.w, vertical: 12.w),
                    decoration: BoxDecoration(
                      color: AppColor.navBgColor,
                      borderRadius: BorderRadius.circular(12.w),
                    ),
                    child: Row(
                      children: [
                        // 左侧标签
                        SizedBox(
                            height: 48.w,
                            child: Align(
                                alignment: Alignment.centerLeft,
                                child: Text(
                                  LocaleKeys.traditionalChinese.tr,
                                  style: TextStyle(
                                    fontSize: 14.sp,
                                    fontWeight: FontWeight.w400,
                                    color:
                                        AppColor.textPrimary.withOpacity(0.94),
                                  ),
                                ))),
                        16.horizontalSpace,
                        const Spacer(),

                        AutoImage(
                          isSimplifiedChinese
                              ? Assets.commonCheckboxNor
                              : Assets.commonCheckboxSel,
                          width: 20.w,
                          height: 20.w,
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          );
        });
  }
}
